package ce.com.newbluedemo.my;

import android.os.Handler;
import android.os.Message;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/11/15 0015.
 */
public class K1_Handler extends Handler {

    private final static String xxx = "xxxx";

    public interface ReceiveBlueDataListen {
        public void receiveData(Message message);
    }

    private ArrayList<ReceiveBlueDataListen> arrayList = new ArrayList<>();


    @Override
    public void handleMessage(Message msg) {
        send(msg);

    }

    public synchronized void addReceiveBlueDataListen(ReceiveBlueDataListen listen) {
        synchronized (xxx) {
            arrayList.add(listen);
        }
    }

    public synchronized void removeReceiveBlueDataListen(ReceiveBlueDataListen listen) {
        synchronized (xxx) {
            arrayList.remove(listen);
        }
    }

    private void send(Message m) {
        synchronized (xxx) {
            for (ReceiveBlueDataListen l : arrayList) {
                if (l != null) {
                    l.receiveData(m);
                }
            }
        }


    }
}
